/*
    SUSAN® - Sole of Unix Save ANything

      Copyright (C) 2011-2016 Skyatlas Co. LTD

   

   
*/

#ifndef BAREOS_SRC_DIRD_SCHEDULER_PRIVATE_H_
#define BAREOS_SRC_DIRD_SCHEDULER_PRIVATE_H_

#include "dird/scheduler_job_item_queue.h"

#include <atomic>
#include <functional>
#include <memory>

namespace directordaemon {

class SchedulerTimeAdapter;

class SchedulerPrivate {
 public:
  ~SchedulerPrivate();
  SchedulerPrivate();

  SchedulerPrivate(const SchedulerPrivate& other) = delete;
  SchedulerPrivate(SchedulerPrivate&& other) = delete;
  SchedulerPrivate& operator=(SchedulerPrivate&& other) = delete;
  SchedulerPrivate& operator=(const SchedulerPrivate& other) = delete;

  void WaitForJobsToRun();
  void FillSchedulerJobQueueOrSleep();
  void AddJobWithNoRunResourceToQueue(JobResource* job, JobTrigger job_trigger);

  std::unique_ptr<SchedulerTimeAdapter> time_adapter;
  SchedulerJobItemQueue prioritised_job_item_queue;
  std::atomic<bool> active{true};

  // testing:
  SchedulerPrivate(std::unique_ptr<SchedulerTimeAdapter> time_adapter,
                   std::function<void(JobControlRecord*)> ExecuteJobCallback);

 private:
  std::function<void(JobControlRecord*)> ExecuteJobCallback_;
  JobControlRecord* TryCreateJobControlRecord(const SchedulerJobItem& next_job);
  void AddJobsForThisAndNextHourToQueue();
  void AddJobToQueue(JobResource* job,
                     RunResource* run,
                     time_t now,
                     time_t runtime,
                     JobTrigger job_trigger);
};

}  // namespace directordaemon

#endif  // BAREOS_SRC_DIRD_SCHEDULER_PRIVATE_H_
